package com.eutray.rest;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.eutray.biz.MissionBiz;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.Iterator;

/**
 * @author ：chenxf
 * @date ：Created in 2019/6/14 10:22
 * @description：
 * @modified By：
 * @version: $
 */
@Slf4j
@RestController
@RequestMapping("Heartbeat")
public class MissionController {
    @Autowired
    private MissionBiz missionBiz;

    @PostMapping("/Index")
    public void query(HttpServletRequest request, HttpServletResponse response) throws Exception{
        Iterator iterator=request.getParameterMap().keySet().iterator();
        if(iterator.hasNext()){
            Object object=iterator.next();
            if(object!=null){
                JSONObject obj=JSON.parseObject((String)object);
                log.debug("Json={}",object);
                String dataResult=missionBiz.getMission(obj.getString("SN"));
                response.setCharacterEncoding("utf-8");
                response.setContentType("application/json;charset=utf-8");
                PrintWriter printWriter=response.getWriter();
                String dataInfoStr= "{\"Data\":\"%s\"}";
                log.debug("result={}",String.format(dataInfoStr,dataResult));
                printWriter.println(String.format(dataInfoStr,dataResult));
                printWriter.flush();
                printWriter.close();
            }
        }

    }

//    @ApiOperation(value = "添加任务 ", notes = "添加任务 ")
//    @PostMapping("/add")
//    public ObjectRestResponse query(@RequestBody MissionInfo missionInfo) {
//        missionBiz.setMission(missionInfo);
//        return ObjectRestResponse.success("设置成功");
//    }
}
